<?php 
	include "../ini.php";
	include "../../libraries/xl_loai_bai_viet.php";
	$dt_loai_bai_viet = new xl_loai_bai_viet;
	
	if (!isset($_GET['id']) || !is_numeric($_GET['id'])){
		$_SESSION['msg'] = "Lỗi! Dữ liệu  không hợp lệ, vui lòng kiểm tra lại";
		$_SESSION['type_msg'] = "error";
		header('Location: '.$_SERVER['HTTP_REFERER']);
		exit;
	}
	$ma = $_GET['id'];
	$loai_bai_viet = $dt_loai_bai_viet->xem($ma);
	
	if($loai_bai_viet == NULL){
		$_SESSION['msg'] = "Lỗi! Dữ liệu không tồn tại, vui lòng kiểm tra lại";
		$_SESSION['type_msg'] = "error";
		header('Location: '.$_SERVER['HTTP_REFERER']);
		exit;
	}
	function in_ten_loai_cha($ds_loai_bai_viet,$ma, $kitu, $machon, $maan){
		foreach($ds_loai_bai_viet as $loai_bai_viet){
			if($loai_bai_viet['ma_loai_cha'] == $ma && $loai_bai_viet['ma'] != $maan){
				if($loai_bai_viet['ma'] == $machon){
					echo '<option selected="selected" value="'.$loai_bai_viet['ma'].'">'.$kitu.$loai_bai_viet['ten'].'</option>';
				}else{
					echo '<option value="'.$loai_bai_viet['ma'].'">'.$kitu.$loai_bai_viet['ten'].'</option>';
				}
				in_ten_loai_cha($ds_loai_bai_viet,$loai_bai_viet['ma'],$kitu.$kitu,$machon,$maan);
			}
		}
	}
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<?php include"../includes/js_css.php"?>
</head>
<body>
<div id="body-wrapper"> <!-- Wrapper for the radial gradient background -->
  
  <?php include"../widgets/sidebar.php"?>
  <!-- End #sidebar -->
  
  <div id="main-content"> <!-- Main Content Section with everything -->
    
    <?php include"../widgets/noscript.php"?>
    <div class="clear"></div>
    <!-- End .clear -->
    
    <div class="content-box"><!-- Start Content Box -->
      
      <div class="content-box-header">
        <h3>Cập nhật loại bài viết</h3>
        <div class="clear"></div>
      </div>
      <!-- End .content-box-header -->
      
      <div class="content-box-content"> 
        
        <!-- End #tab1 -->
        
        <div class="tab-content default-tab" id="tab2">
          <form name="f3" id="f3" action="edit_sm.php" method="post" onsubmit="return kiemtra()">
          	<input  name="ma" id="ma" type="hidden" value="<?php echo $loai_bai_viet["ma"];?>"/>
            <fieldset>
              <!-- Set class to "column-left" or "column-right" on fieldsets to divide the form into columns -->
            <table width="100%" border="0">
              <tbody>
              	<tr class="alt-row">
                  <td colspan="2"><?php message() ?></td>
                  
                </tr>
                <tr class="alt-row">
                  <td width="25%">Tên Loại Bài Viết</td>
                  <td width="75%"><input class="text-input medium-input datepicker" type="text" id="ten" name="ten" value="<?php echo $loai_bai_viet["ten"];?>" /></td>
                </tr>
                <tr>
                  <td>Tên Loại Cha</td>
                  <td><select class="small-input" name="ma_loai_cha">
                      <option style="text-align:center" value="0" name="ma_loai_cha" id="ma_loai_cha">-- No Parent --</option>
					  <?php 
						  $ds_loai_bai_viet = $dt_loai_bai_viet->danh_sach_all();
						  in_ten_loai_cha($ds_loai_bai_viet,0,'==',$loai_bai_viet["ma_loai_cha"],$loai_bai_viet["ma"]);
					  ?>                   
                    </select></td>
                </tr>
                <tr class="alt-row">
                  <td>Thứ Tự Hiển Thị</td>
                  <td><input class="text-input medium-input datepicker" type="text" id="thu_tu_hien_thi" name="thu_tu_hien_thi" value="<?php echo $loai_bai_viet["thu_tu_hien_thi"];?>"/></td>
                </tr>
                <tr>
                  <td>Mô tả</td>
                  <td><textarea class="text-input textarea" id="mo_ta" name="mo_ta" cols="20" rows="5"><?php echo $loai_bai_viet["mo_ta"];?></textarea></td>
                </tr>
                <tr>
                  <td style="text-align:center !important" colspan="2">
                  	<input class="button" type="submit" value="Cập nhật" name="luu_va_thoat">
                  
                    <input class="button" type="button" value="Không lưu" onclick="window.location.href='list.php'"></td>
                </tr>
              </tbody>
            </table>
            </fieldset>
            <div class="clear"></div>
            <!-- End .clear -->
            
          </form>
        </div>
        <!-- End #tab2 --> 
        
      </div>
      <!-- End .content-box-content --> 
      
    </div>
    <!-- End .content-box -->
    
    <div class="clear"></div>
    <?php include"../widgets/footer.php"?>
  </div>
  <!-- End #main-content --> 
  
</div>
</body>
</html>
